import 'dart:convert';

import 'package:flutter_web_server/ImcludeServer.dart';

class ServerR {
  String? msg;
  String? code;
  dynamic data;

  ServerR({
    this.msg,
    this.code,
    this.data,
  });

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['msg'] = this.msg;
    data['code'] = this.code;
    data['data'] = this.data;
    return data;
  }
}

extension ServerRExt on ServerR {
  Response toOK() {
    code = "1";
    msg ??= "ok";
    return Response(HttpStatus.ok, body: jsonEncode(this), headers: {'Content-Type': 'application/json'},);
  }

  Response toError() {
    code = "0";
    msg ??= "error";
    return Response(HttpStatus.ok, body: jsonEncode(this), headers: {'Content-Type': 'application/json'},);
  }
}
